package com.ruihai.tutorial.faceplusplus.service;

import com.ruihai.tutorial.faceplusplus.common.CommonConstants;
import com.ruihai.tutorial.faceplusplus.common.FacePPHttpExecutor;

import java.util.HashMap;

/**
 * Face++ related services for face detection, face analyze etc..
 * Created by Tim on 2017/11/8.
 */
public class FacePPService {

    private static HashMap<String, String> defaultAuthParams;

    static {
        defaultAuthParams = new HashMap<>();
        defaultAuthParams.put(CommonConstants.FACE_PP_API_KEY_NAME, CommonConstants.FACE_PP_API_KEY);
        defaultAuthParams.put(CommonConstants.FACE_PP_API_SECRET_NAME, CommonConstants.FACE_PP_API_SECRET);
    }

    /**
     * Face++ face detect service.
     * @param buff
     * @return
     */
    public String faceDetectionService(byte[] buff) {

        HashMap<String, byte[]> byteMap = new HashMap<>();
        byteMap.put("image_file", buff);
        try{
            byte[] bacd = FacePPHttpExecutor.post(CommonConstants.FACE_PP_DETECT_URL, defaultAuthParams, byteMap);
            return new String(bacd);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

}
